<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #app{
            width: 350px;
        }
        img{
            width: 100%;
            display: block;
        }
    </style>
</head>
<body>
    <div id="app"></div>
    <script>
        function loadImg(url){
            let image = new Image();
            return new Promise((resolve,reject)=>{
                image.src = url;
                image.onload = function(e){
                    resolve({e,image})
                }
                image.onerror = function(e){
                    reject({e,image})
                }
            })
        }

        loadImg("/img/img1.jpg",document.querySelector('#app')).then(({e,image}) => {
            // 图片实际宽高
            console.log(image.offsetWidth)
            // 如果offsetWidth > 0, 那么，image.width取offsetWidth
            // f否则，取图片原始宽高
            console.log(image.width)
            // 原始图片宽高
            console.log(image.naturalWidth)
        }).catch(e=>{

        })
    </script>
</body>
</html>